package com.yu.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yu.app.pojo.OrderInfo;
import com.yu.app.pojo.vo.HistoryOrderVO;
import com.yu.common.enums.OrderStatus;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface OrderMapper extends BaseMapper<OrderInfo> {

    // 完成订单的交易号，微信回调调用
    @Update("UPDATE order_info SET order_status=#{param2}, wx_pay_transaction_id=#{param3}, pay_price=#{param4}  " +
            " WHERE order_no=#{param1} and wx_pay_transaction_id is null; ") // 让回调通知去填交易号
    int finishPayOrder(String orderNo, String orderStatus, String wxPayTransactionId, Integer payPrice);

    // 分页获取历史订单
    @Select("select order_no as orderNo, " +
            "order_status as orderStatus, " +
            "goods_preview as goodsPreview, " +
            "goods_total_num as goodsTotalNum, " +
            "create_time as createTime, " +
            "pay_price as payPrice " +
            "from order_info where wx_openid = #{param1} order by create_time desc limit #{param2},#{param3};")
    List<HistoryOrderVO> getHistoryOrderByPage(String wxOpenid, Integer rowStart, Integer pageSize);
    // 分页获取历史订单, 获取总数
    @Select("select count(*) from order_info where wx_openid = #{param1}; ")
    int getHistoryOrderTotalCount(String wxOpenid);

    @Update("update order_info set order_status = #{param2} where order_no = #{param1}")
    int updateOrderStatus(String orderNo, String orderStatus);
}
